#include <iostream>
using namespace std;
#define maxn 21
int f[maxn]; //f[i]为第i个节点结束时的最大值
int map[maxn][maxn], cost[maxn], prenode[maxn], N, total, terminateNode;
void printPath(int term)
{
    if (term == 0)
        return;
    printPath(prenode[term]);
    cout << term << " ";
}
int main()
{
    cin >> N;
    for (int i = 1; i <= N; ++i)
    {
        cin >> cost[i];
    }
    for (int i = 1; i < N; ++i)
    {
        for (int j = i + 1; j <= N; ++j)
        {
            cin >> map[i][j]; //DAG
        }
    }
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; ++j)
        {
            if (map[j][i] == 1 && f[j] > f[i])
                f[i] = f[j], prenode[i] = j;
        }
        f[i] += cost[i];
        if (f[i] > total)
            total = f[i], terminateNode = i;
    }
    printPath(terminateNode);
    cout << endl
         << total << endl;
    return 0;
}